package com.jyb.qiyefuwu.view.activity.usercenter;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.android.material.tabs.TabLayout;
import com.jyb.qiyefuwu.R;
import com.jyb.qiyefuwu.databinding.ActivityFwSaleorderBinding;
import com.jyb.qiyefuwu.router.PathHome;
import com.jyb.qiyefuwu.uitls.CommPagerAdapter3;
import com.jyb.qiyefuwu.view.fragment.usercenter.SaleCopyrightListFragment;
import com.jyb.qiyefuwu.view.fragment.usercenter.SalePantentListFragment;
import com.jyb.qiyefuwu.view.fragment.usercenter.SaleTrademarkListFragment;
import com.jyb.qiyefuwu.viewmodel.SaleOrderViewModel;
import com.swgk.core.common.base.BaseActivity;

import java.util.ArrayList;
@Route(path = PathHome.SaleOrderListActivity)
public class SaleOrderListActivity extends BaseActivity<SaleOrderViewModel, ActivityFwSaleorderBinding> {
    @Override
    protected int layoutId() {
        return R.layout.activity_fw_saleorder;
    }

    @Override
    protected void createViewModel() {
        mViewModel = new ViewModelProvider(this).get(SaleOrderViewModel.class);
    }

    private ArrayList<Fragment> fragmentList = new ArrayList<>();

    @Override
    protected void init() {
        fragmentList.add(SaleTrademarkListFragment.newInstance());
        fragmentList.add(SalePantentListFragment.newInstance());
        fragmentList.add(SaleCopyrightListFragment.newInstance());
        CommPagerAdapter3 pagerAdapter = new CommPagerAdapter3(getSupportFragmentManager(), fragmentList, mViewModel.title);
        mBinding.viewpager.setAdapter(pagerAdapter);
        mBinding.tabActionBar.setupWithViewPager(mBinding.viewpager);
        mBinding.backView.setOnClickListener(this);
        View linearLayout = LayoutInflater.from(this).inflate(R.layout.item_tab_publish, null);
        TextView selectTextView = linearLayout.findViewById(R.id.tab_item_textview);
        mBinding.tabActionBar.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                selectTextView.setText(tab.getText());
                tab.setCustomView(linearLayout);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        selectTextView.setText(mBinding.tabActionBar.getTabAt(0).getText());
        mBinding.tabActionBar.getTabAt(0).setCustomView(linearLayout);
        mBinding.tabActionBar.getTabAt(0).select();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v.getId() == R.id.back_view) {
            finish();
        }
    }
}
